import axios from "axios"
import {Message} from "element-ui"
import local from '@/utils/local'
// 设置统一服务器地址

axios.defaults.baseURL='http://129.211.169.131:21001'



// 设置请求拦截

axios.interceptors.request.use(config=>{
    let token = local.get('token');
    if(token){
        //加上token                  Bearer
        config.headers.Authorization=token 
    }
    return config
})

//响应拦截
axios.interceptors.response.use(response=>{
    // log一下response 看后端如何返回数据
    if(response.data.code !==undefined &&  response.data.msg !==undefined){
        let { code ,msg} =response.data
        if(code===0){
            Message({
                message:msg,
                type:'success'
            })
        }else if(code ===1){
            Message({
                message:msg,
                type:'error'
            })
        }else{
            Message({
                message:msg,
                type:'error'
            })
        }
    }
    return response
})



//暴露出去 

export default axios 